<% content_for :css do %>
  <%= stylesheet_link_tag 'dospy_waters_new' %>
<% end %>
<% content_for :javascript do %>
<script>

  var forums_count = 0;
  function loading() {
    forums_count = 0;
    $$('input.checkbox').each(function(checkbox) {
      if(checkbox.checked == true) {
        forums_count = forums_count + 1 ;
      }
    });
    $('water_button').update('灌水中...');
  }

  function complete() {
    if(forums_count == 1) {
      $('water_button').update('开始灌水');
    } else {
      forums_count = forums_count - 1;
    }
  }
  function watering() {
    loading();
  <% @forums.keys.each do |key| %>
    if($F('water_<%= key %>') == 'yes') {
      <%= remote_function :update => "forum_#{key}" ,
            :url => dospy_waters_url,
            :with => "$('#{key}_forum_form').serialize() + $('proxy_form').serialize()",
            :method => :post,
            :loading => "$('#{key}_result').update('灌水中...');$('#{key}_result').className='water_result'",
            :complete => 'complete()'
       %>
    }
  <% end %>
  }
</script>
<% end %>
<%= render :file => 'infos/_nav_bar.html' %>
<div id='new_dospy_water'>
  <div class="head">
    <div class="title">
      <h1>塞班灌水</h1>
    </div>
    <div class="tools">
      <%= link_to_function '开始灌水','watering()', :id => 'water_button' %>
    </div>
  </div>
  <div class="tip"></div>
  <div id="forms">
    <% form_tag '#', :id => 'proxy_form' do %>
    <dl class="proxy">
      <dt>代理：</dt>
      <dd><%= text_field_tag 'task[proxy_ip_and_port]' %></dd>
    </dl>
    <% end %>
    <% @forums.keys.each do |key|  %>
      <% task = @today_tasks.find_by_forum_code(key) %>
      <div id="forum_<%= key %>">
        <%= render :partial => 'show.html', :locals => { :task => task, :forum_code => key, :forum_url => @forums[key]  }%>  
      </div>      
    <% end %>
  </div>
</div>